New method (GtkBuilderConverter._create_object): Conditionally take a node
authorJohan Dahlin <johan@gnome.org>
Fri, 18 Jan 2008 16:09:26 +0000 (16:09 +0000)
committerJohan Dahlin <johan@src.gnome.org>
Fri, 18 Jan 2008 16:09:26 +0000 (16:09 +0000)
2008-01-18  Johan Dahlin  <johan@gnome.org>

* gtk/gtk-builder-convert (get_property_node): New method
(GtkBuilderConverter._create_object): Conditionally take a node as
a property value, so don't lose translate/context attributes if they
are set.
(GtkBuilderConverter._add_action_from_menuitem): Send in Node as
property values instead of strings.
(#509153, Erik van Pienbroek)

svn path=/trunk/; revision=19383

ChangeLog
gtk/gtk-builder-convert

index 1d303b7f90ac26dfd437900c6eec5cc81dcd4af1..89b77fefa3067029f30774950143000d6ade3f9d 100644 (file)
--- a/ChangeLog
+++ b/ChangeLog
@@ -1,3 +1,13 @@
+2008-01-18  Johan Dahlin  <johan@gnome.org>
+
+       * gtk/gtk-builder-convert (get_property_node): New method
+       (GtkBuilderConverter._create_object): Conditionally take a node as
+       a property value, so don't lose translate/context attributes if they
+       are set. 
+       (GtkBuilderConverter._add_action_from_menuitem): Send in Node as
+       property values instead of strings.
+       (#509153, Erik van Pienbroek)
+
 2008-01-16  Mathias Hasselmann  <mathias@openismus.com>
 
        Change GtkCalendarDetailFunc to return newly allocated string. (#339540)
index 8e5d0892a252875b90a67abad12ab289bd902b54..3544e221acb719aac25213b96ac83abc4822a668 100755 (executable)
@@ -82,6 +82,17 @@ def get_property(node, property_name):
     properties = get_properties(node)
     return properties.get(property_name)
 
+def get_property_node(node, property_name):
+    assert node.tagName == 'object'
+    properties = {}
+    for child in node.childNodes:
+        if child.nodeType == Node.TEXT_NODE:
+            continue
+        if child.tagName != 'property':
+            continue
+        if child.getAttribute('name') == property_name:
+            return child
+
 def get_signal_nodes(node):
     assert node.tagName == 'object'
     signals = []
@@ -126,9 +137,11 @@ def get_object_node(child_node):
 def copy_properties(node, props, prop_dict):
     assert node.tagName == 'object'
     for prop_name in props:
-        value = get_property(node, prop_name)
-        if value is not None:
-            prop_dict[prop_name] = value
+        child = get_property_node(node, prop_name)
+        if child is not None:
+            prop_dict[prop_name] = child
+
+    return node
 
 class GtkBuilderConverter(object):
 
@@ -166,6 +179,21 @@ class GtkBuilderConverter(object):
                       if w.getAttribute(attribute) == value]
 
     def _create_object(self, obj_class, obj_id, template=None, **properties):
+        """
+        Creates a new <object> tag.
+        Optionally a name template can be provided which will be used
+        to avoid naming collisions.
+        The properties dictionary can either contain string values or Node
+        values. If a node is provided the name of the node will be overridden
+        by the dictionary key.
+
+        @param obj_class: class of the object (class tag)
+        @param obj_id: identifier of the object (id tag)
+        @param template: name template to use, for example 'button'
+        @param properties: dictionary of properties
+        @type properties: string or Node.
+        @returns: Newly created node of the object
+        """
         if template is not None:
             count = 1
             while True:
@@ -180,9 +208,15 @@ class GtkBuilderConverter(object):
         obj.setAttribute('class', obj_class)
         obj.setAttribute('id', obj_id)
         for name, value in properties.items():
-            prop = self._dom.createElement('property')
+            if isinstance(value, Node):
+                # Reuse the node, so translatable and context still will be
+                # set when converting nodes. See also #509153
+                prop = value
+            else:
+                prop = self._dom.createElement('property')
+                prop.appendChild(self._dom.createTextNode(value))
+
             prop.setAttribute('name', name)
-            prop.appendChild(self._dom.createTextNode(value))
             obj.appendChild(prop)
         self.objects[obj_id] = obj
         return obj
@@ -371,18 +405,18 @@ class GtkBuilderConverter(object):
             if (children and
                 children[0].getAttribute('internal-child') == 'image'):
                 image = get_object_node(children[0])
-                stock_id = get_property(image, 'stock')
-                if stock_id is not None:
-                    properties['stock_id'] = stock_id
+                child = get_property_node(image, 'stock')
+                if child is not None:
+                    properties['stock_id'] = child
         elif object_class == 'GtkSeparatorMenuItem':
             return
         else:
             raise NotImplementedError(object_class)
 
         if get_property(node, 'use_stock') == 'True':
-            stock_id = get_property(node, 'label')
-            if stock_id is not None:
-                properties['stock_id'] = stock_id
+            child = get_property_node(node, 'label')
+            if child:
+                properties['stock_id'] = child
 
         properties['name'] = object_id
         action = self._create_object(name,